﻿using Microsoft.Win32;

namespace Toybox.CookieGetterSharp.SQLite
{
  // CookieGetter は GoogleChrome のを使用。
  
  class ChromePlusBrowserManager : IBrowserManager
  {
    const string INSTDIR = "Software\\ChromePlus";
    const string COOKIEPATH = "\\ChromePlusUserData\\Default\\Cookies";
    
    #region IBrowserManager メンバ

    public BrowserType BrowserType
    {
      get { return BrowserType.ChromePlus; }
    }

    public ICookieGetter CreateDefaultCookieGetter()
    {
      //string path = Utility.ReplacePathSymbols(COOKIEPATH);
      string path = null;
      try
      {
        using (RegistryKey rKey = Registry.CurrentUser.OpenSubKey(INSTDIR))
        {
          path = rKey.GetValue("Install_Dir") as string;
        }
        path += COOKIEPATH;
      }
      catch
      {
        //throw;
      }

      if (!System.IO.File.Exists(path))
      {
        path = null;
      }

      CookieStatus status = new CookieStatus(this.BrowserType.ToString(), path, this.BrowserType, PathType.File);
      return new GoogleChromeCookieGetter(status);
    }

    public ICookieGetter[] CreateCookieGetters()
    {
      return new ICookieGetter[] { CreateDefaultCookieGetter() };
    }

    #endregion
  }
}
